<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>dialog弹框</title>
  <style>
	  dialog::backdrop {
		  background: red;
		}
		button {display: block;}
	</style>
	<script>
	  i = 0
	</script>
</head>
<body>
<!--open属性相当于调用show方法-->
<dialog id="dialog" onclick="this.close(++i)">
  <p>Greetings, one and all!</p>
</dialog>
	<button onclick="dialog.showModal()">showModal</button>
	<button onclick="dialog.show()">show</button>
	<script>
	// showModal: Displays the dialog as a modal, over the top of any other dialogs that might be present.
	// Interaction outside the dialog is blocked.
	// User may press the "Escape" key to close the modal.
	// backdrop pseudo element will effect


	// show: still allowing interaction with content outside of the dialog.

	// close(value): close the dialog, an optional DOMString may be passed as an argument, updating the returnValue of the the dialog

	dialog.onclose = function(e) {
	  console.log('dialog returnValue: ' + e.target.returnValue)
	}
	</script>
	<!-- Simple pop-up dialog box, containing a form -->
<dialog id="favDialog">
  <form method="dialog">
    <section>
      <p><label for="favAnimal">Favorite animal:</label>
      <select id="favAnimal" name="favAnimal">
        <option></option>
        <option>Brine shrimp</option>
        <option>Red panda</option>
        <option>Spider monkey</option>
      </select></p>
    </section>
    <menu>
      <button id="cancel" type="reset">Cancel</button>
      <button type="submit">Confirm</button>
    </menu>
  </form>
</dialog>

<menu>
  <button id="updateDetails">Update details</button>
</menu>

<script>
  (function() {
    var updateButton = document.getElementById('updateDetails');
    var cancelButton = document.getElementById('cancel');

    // Update button opens a modal dialog
    updateButton.addEventListener('click', function() {
      document.getElementById('favDialog').showModal();
    });

    // Form cancel button closes the dialog box
    cancelButton.addEventListener('click', function() {
      document.getElementById('favDialog').close();
    });

  })();
</script>
</body>
</html>
